package cn.stylefeng.guns.modular.controller;

import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.modular.entity.Room;
import cn.stylefeng.guns.modular.service.RoomsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 李宝嘉
 * @Date 2021/12/23 14:25
 */
@RestController
@RequestMapping("/rooms")
public class RoomsController {
    @Resource
    private RoomsService roomsService;

    @GetMapping("/get")
    public ResponseData get(@RequestParam String roomId) {
        return new SuccessResponseData(roomsService.getRoomDetail(roomId));
    }

    @PostMapping("/add")
    public ResponseData add(@RequestBody Room room) {
        roomsService.add(room);
        return new SuccessResponseData();
    }

    @PostMapping("/update")
    public ResponseData update(@RequestBody Room room) {
        roomsService.updateById(room);
        return new SuccessResponseData();
    }

    @GetMapping("/delete")
    public ResponseData delete(@RequestParam Long roomId) {
        roomsService.removeById(roomId);
        return new SuccessResponseData();
    }

    @GetMapping("/list")
    public ResponseData list() {
        return new SuccessResponseData(roomsService.list());
    }

    @GetMapping("/tree")
    public ResponseData tree() {
        return new SuccessResponseData(roomsService.tree());
    }

    @GetMapping("/get/level/top")
    public ResponseData getTopLevel() {
        return new SuccessResponseData(roomsService.getTopLevel());
    }
}
